<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('基础抽取列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>数据源：</label>
                            <select name="idDb" class="form-control m-b" th:with="type=${@baseDbService.selectAll()}">
                                <option value=""></option>
                                <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.idDb}"></option>
                            </select>
                        </li>
                        <li>
                            <label>抽取分类：</label>
                            <select name="sdDrawcls" class="form-control m-b" th:with="type=${@baseSd.getItem('draw_cls')}">
                                <option value=""></option>
                                <option th:each="item : ${type}" th:text="${item.na}" th:value="${item.cd}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:etl:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:etl:remove')}]];
    var prefix = ctx + "etl/dw";
    var sdSysData = [[${@baseSd.getItem('hos_sys')}]];
    var drawClsData = [[${@baseSd.getItem('draw_cls')}]];
    var dbData = [[${@baseDbService.selectAll()}]];

    function submitHandler() {
        if ($.validate.form()) {
            var rows = $("#"+table.options.id).bootstrapTable('getSelections');
            if(rows.length==0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            var idBases="";
            $.each(rows,function (index,item) {
                idBases += item.idDrawBase;
            });
            $.ajax({
                url: prefix+"/addList/"+idBases,
                cache: false,
                type: 'GET',
                async: false,
                dataType: 'json',
                success: function (result) {
                    if(result.code==0) {
                        $("#bootstrap-table").bootstrapTable('refreshOptions',{pageNumber:1});
                    }
                    $.modal.close();
                }
            });
        }
    }

    $(function() {
        var options = {
            url: "/etl/base/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "基础抽取",
            columns: [{
                checkbox: true
            },
                {
                    field: 'idDrawBase',
                    title: '',
                    visible: false
                },
                {
                    field: 'na',
                    title: '名称'
                },
                {
                    field: 'sdSys',
                    title: '系统',
                    formatter: function(value, item, index) {
                        return $.table.selectSdNaByCd(sdSysData, item.sdSys);
                    }
                },
                {
                    field: 'idDb',
                    title: '数据源'
                },
                {
                    field: 'sdDrawcls',
                    title: '抽取分类',
                    formatter: function(value, item, index) {
                        return $.table.selectSdNaByCd(drawClsData, item.sdDrawcls);
                    }
                },
                {
                    field: 'cdTbTar',
                    title: '目标表'
                }]
        };
        $.table.init(options);
    });
</script>
</body>
</html>